package com.yuezhu.constomview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yuezhu.R;


/**
 * 根据状态显示状态视图 * @author Tony
 * 
 */
public class WebStatusView extends LinearLayout {
	public static final int NO_DATA = 1;// 无数据状态
	public static final int INIT = 0;// 初始状态
	public static final int NO_NET = -1;// 无网络状态
	public static final int PROGRESSING = 2;// 加载中状态
	public  static  final  int PROGRESSING_WITH_BACK = 3;// 带背景的加载中状态
	public  static  final int NO_DATA_WITH_BUTTON = 4;//带登录按钮或添加偏好路线按钮
	private LinearLayout mLlNoData;// 无数据视图
	private LinearLayout mLlNoNet;// 无网络视图
	private LinearLayout mLlProgress;// 加载视图
	private TextView mTvMsg, login_text;// 无数据下提示文字
	private int status = 0;// 状态控制,0为都不显示，1为显示无数据，-1为显示无网络，2为加载中
	private RelativeLayout immediately_get1;
	private ImageView nodate_img;
	public WebStatusView(Context context) {
		super(context);
		initView(context);
	}

	public WebStatusView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(context);
	}

	public WebStatusView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		initView(context);
	}

	private void initView(Context context) {
		View view = LayoutInflater.from(context).inflate(
				R.layout.ll_nodatareceive, this);
		mLlNoData = (LinearLayout) view.findViewById(R.id.ll_nodata_webstatus);
		mLlNoNet = (LinearLayout) view.findViewById(R.id.ll_nonet_webstatus);
		mLlProgress = (LinearLayout) view
				.findViewById(R.id.ll_progress_webstatus);
		mTvMsg = (TextView) view.findViewById(R.id.tv_msg_webstatus);
		immediately_get1 = (RelativeLayout) view
				.findViewById(R.id.invoice_detail_immediately_get1);
		login_text = (TextView) view
				.findViewById(R.id.invoice_detail_immediately_get);
		nodate_img = (ImageView) view.findViewById(R.id.img11);
		mLlProgress.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

			}
		});
		setStatus(status);
	}
public View getProgressView(){
	mLlProgress.setBackgroundColor(0);
	return mLlProgress;
}
	/**
	 * 设置点击事件
	 */
	public void setOnClickListener(OnClickListener listenser) {
		mLlNoNet.setOnClickListener(listenser);
	}
	/**
	 * 设置点击事件
	 */
	public void setOnNoNetClickListener(OnClickListener listenser) {
		immediately_get1.setOnClickListener(listenser);
		mLlNoNet.setOnClickListener(listenser);
	}
	/**
	 * 设置文本
	 * 
	 * @param Msg
	 */
	public void setMsg(String msg) {
		if (msg != null)
			mTvMsg.setText(msg);
	}
	public void setNoLogin(String content, String button_text){
		setStatus(NO_DATA_WITH_BUTTON);
		mTvMsg.setText(content);
		login_text.setText(button_text);
		nodate_img.setVisibility(View.GONE);
	}
	public  void setNoPreDate(String content, String button_text){
		setStatus(NO_DATA_WITH_BUTTON);
		mTvMsg.setText(content);
		login_text.setText(button_text);
		nodate_img.setVisibility(View.VISIBLE);
	}
	public  void setNoDate(String msg){
		setStatus(NO_DATA);
		login_text.setVisibility(View.GONE);
		mTvMsg.setText(msg);
	}
	/**
	 * 视图状态设置
	 */
	public void setStatus(int status) {
		if (status == INIT) {
			mLlNoData.setVisibility(View.GONE);
			mLlNoNet.setVisibility(View.GONE);
			mLlProgress.setVisibility(View.GONE);
		} else if (status == NO_DATA) {
			mLlNoData.setVisibility(View.VISIBLE);
			immediately_get1.setVisibility(View.GONE);
			mLlNoNet.setVisibility(View.GONE);
			mLlProgress.setVisibility(View.GONE);
		} else if (status == NO_DATA_WITH_BUTTON) {
			mLlNoData.setVisibility(View.VISIBLE);
			immediately_get1.setVisibility(View.VISIBLE);
			mLlNoNet.setVisibility(View.GONE);
			mLlProgress.setVisibility(View.GONE);
		}else if (status == NO_NET) {
			mLlNoData.setVisibility(View.GONE);
			mLlNoNet.setVisibility(View.VISIBLE);
			mLlProgress.setVisibility(View.GONE);
		} else if (status == PROGRESSING) {
			mLlNoData.setVisibility(View.GONE);
			mLlNoNet.setVisibility(View.GONE);
			mLlProgress.setVisibility(View.VISIBLE);
			mLlProgress.setBackgroundColor(0);
		}else if (status == PROGRESSING_WITH_BACK) {
			mLlNoData.setVisibility(View.GONE);
			mLlNoNet.setVisibility(View.GONE);
			mLlProgress.setVisibility(View.VISIBLE);
			mLlProgress.setBackgroundColor(getContext().getResources().getColor(R.color.white));
		}
	}

	/**
	 * 获取当前显示状态码
	 * 
	 * @return
	 */
	public int getStatus() {
		return status;
	}
}
